package com.jkt.rms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;

import com.jkt.rms.businessservice.ResourceBusinessService;
import com.jkt.rms.commons.utils.RMSException;
import com.jkt.rms.commons.utils.ServiceLocator;
import com.jkt.rms.vo.ResourceRoleVO;
import com.jkt.rms.vo.ResourceVO;

public class ResourceController extends AbstractMultiActionController {
	private static final Logger LOG = Logger.getLogger(ResourceController.class);
	private ResourceBusinessService resourceBusinessService = ServiceLocator.getServiceLocator().locate("resourceBusinessService");
	
	public ModelAndView showUI(HttpServletRequest request,HttpServletResponse response , ResourceVO resourceVO) throws RMSException {
		LOG.info("Method showUI (...) invoked");
		loadInitData(resourceVO);
		return new ModelAndView("addSearchResource", "cmdResource",resourceVO);
	
	}
	private List<ResourceRoleVO> getProjectRole() {
		List<ResourceRoleVO> prjRoleVOList = null;
		try {
			prjRoleVOList =   resourceBusinessService.findProjectRole();
		} catch (RMSException e) {
			LOG.debug("[Exception in loadProjectRole]",e.getCause());
		}
		return prjRoleVOList;
	}
	
	
	private void loadInitData(ResourceVO resourceRoleVO){
		resourceRoleVO.setProjectRoleList(getProjectRole());
		try {
			resourceRoleVO.setVendorList(resourceBusinessService.findVendor());
			resourceRoleVO.setLocationList(resourceBusinessService.findLocation());
			resourceRoleVO.setProjectList(resourceBusinessService.findAllActiveProject());
		} catch (RMSException e) {
			LOG.debug("[Exception in loadVendor]",e.getCause());
		}
	}
	
	
	
}
